<?php
namespace ManiaLivePlugins\MLEPP\HeadsUp\Gui\Windows;
use ManiaLive\PluginHandler\PluginHandler;
use ManiaLive\Gui\Windowing\Controls\Frame;
use ManiaLib\Gui\Elements\Label;
use ManiaLib\Gui\Elements\Bgs1;
use ManiaLib\Gui\Elements\BgsPlayerCard;
use ManiaLib\Gui\Elements\Quad;
use ManiaLib\Gui\Layouts\Flow;
use ManiaLivePlugins\MLEPP\Core\Core;
use ManiaLivePlugins\MLEPP\HeadsUp\HeadsUp;
class HeadsUpWidget extends \ManiaLive\Gui\Windowing\Window
{
    protected $frame;
    protected $quad;
    private $label;
    public $callback;
    protected $background;

    function initializeComponents()
    {
        $this->frame = new Frame();
        $this->frame->setPosition(0, 0);
        $this->addComponent($this->frame);

        $this->quad = new Quad();
		$this->quad->setStyle("Bgs1");
		$this->quad->setSubStyle("BgButtonGrayed");
        $this->quad->setUrl(HeadsUp::$website);
        $this->frame->addComponent($this->quad);
        $this->label = new Label();
        $this->frame->addComponent($this->label);
    }

    function onLoad() {

    }

    function onDraw() {
       $text = $this->label->getText();
        $lines = explode("\n",$text);
        $textYsize = count($lines)*$this->label->getTextSize()+1;
        $this->frame->setSize($this->sizeX+8, $textYsize+12);
        $this->label->setSize($this->sizeX, $textYsize);
        $this->quad->setSize($this->sizeX+8, $textYsize+1);
        $this->label->setPosition(0,1.5);
        $this->quad->setPosition(0,0);
        $this->label->setHalign("center");
        $this->quad->setHalign("center");
        $this->label->setValign("top");
        $this->quad->setValign("top");
        $this->frame->setScale(0.6,0.6);
    }

    function onResize()
    {

    }
    function setText($text)
    {
        $this->label->setText(str_replace("|","\n",$text));
        $this->label->setTextSize(4);
    }
	function destroy() {
		unset($this->callback);
		parent::destroy();
	}
}
?>